<template>
  <div class="box">
    <div class="f1">
      <ul v-show="status != 'lbzs'">
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组30.png" alt="" />
            <div class="icon2"></div>
          </div>
          <span>填写申请信息</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组32.png" alt="" />
            <div class="icon2"></div>
          </div>
          <span>上传申请资料</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组34.png" alt="" />
          </div>
          <span>业务提交完成</span>
        </li>
      </ul>
      <ul v-show="status == 'lbzs'">
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组30.png" alt="" />
            <div class="icon2 zssq"></div>
          </div>
          <span style="margin-left: -10px">企业认证</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组33.png" alt="" />
            <div class="icon2 zssq"></div>
          </div>
          <span>填写申请信息</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组34.png" alt="" />
            <div class="icon2 zssq"></div>
          </div>
          <span>上传申请资料</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组36.png" alt="" />
          </div>
          <span>业务提交完成</span>
        </li>
      </ul>
    </div>

    <div class="f2">
      <ul class="ul">
        <li>
          <el-form
            id="altitude"
            :model="form"
            label-width="220px"
            :rules="rules"
          >
            <el-form-item label="担保模式" prop="a">
              <el-select @change="a" v-model="form.a" placeholder="">
                <el-option key="99" label="请选择" value=""></el-option>
                <el-option
                  key="1"
                  label="汇总征税"
                  value="汇总征税"
                ></el-option>
                <el-option
                  key="2"
                  label="征税要素"
                  value="征税要素"
                ></el-option>
                <el-option
                  key="3"
                  label="纳税期限"
                  value="纳税期限"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-form :model="form" label-width="220px" :rules="rules">
            <el-form-item label="当期财报年份" prop="f">
              <el-date-picker
                :clearable="false"
                v-model="form.f"
                @change="a"
                type="year"
                placeholder=""
                value-format="YYYY"
              >
              </el-date-picker>
            </el-form-item>
          </el-form>
        </li>
        <li>
          <el-form
            class="enterpriseName"
            :model="form"
            label-width="220px"
            :rules="rules"
          >
            <el-form-item label="担保起始日期" prop="g">
              <el-date-picker
                style="width: 300px"
                size="large"
                :clearable="false"
                v-model="form.g"
                type="date"
                placeholder="请选择日期"
                value-format="YYYY-MM-DD"
              >
              </el-date-picker>
            </el-form-item>
          </el-form>
          <el-form :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业当期年度资产合计" prop="h">
              <el-input
                v-model="addform.h"
                @focus="
                  () => {
                    this.addform.h = remoney(this.addform.h);
                  }
                "
                placeholder=""
                @blur="h"
              ></el-input>
              <p
                style="
                  position: absolute;
                  right: 15px;
                  top: 5px;
                  z-index: 999;
                  font-size: 16px;
                "
              >
                元
              </p>
              <p class="message" v-if="h1">格式错误，请重新输入</p>
            </el-form-item>
          </el-form>
        </li>
        <li>
          <el-form :model="form" label-width="220px" :rules="rules">
            <el-form-item label="担保金额" prop="i">
              <el-input
                v-model="addform.i"
                @focus="
                  () => {
                    this.addform.i = remoney(this.addform.i);
                  }
                "
                @input="limitInput($event, 'i')"
                placeholder=""
                @blur="i"
              ></el-input>
              <p
                style="
                  position: absolute;
                  right: 15px;
                  top: 5px;
                  z-index: 999;
                  font-size: 16px;
                "
              >
                元
              </p>
              <p class="message" v-if="i1">格式错误，请重新输入</p>
            </el-form-item>
          </el-form>

          <el-form :model="form" label-width="220px" :rules="rules">
            <el-form-item label="企业当期年度负债合计" prop="j">
              <el-input
                v-model="addform.j"
                @focus="
                  () => {
                    this.addform.j = remoney(this.addform.j);
                  }
                "
                placeholder=""
                @blur="j"
              ></el-input>
              <p
                style="
                  position: absolute;
                  right: 15px;
                  top: 5px;
                  z-index: 999;
                  font-size: 16px;
                "
              >
                元
              </p>
              <!--       @input="limitInput($event, 'j')" -->
              <p class="message" v-if="j1">格式错误，请重新输入</p>
            </el-form-item>
          </el-form>
        </li>
      </ul>

      <!-- 上一步/保存/提交 按钮 -->
      <div class="submit">
        <!-- <el-tooltip placement="top" v-if="!btn"> -->
        <!-- <div slot="content">请勾选授权协议<br />确认填写的信息是否完整</div> -->

        <button
          class="btn btn3 active"
          @click="addKJApplys()"
          :class="{ actives: submitMessage == '提交中' }"
        >
          {{ submitMessage }}
        </button>
        <!-- </el-tooltip> -->
      </div>
    </div>
  </div>
</template>

<script>
import { Contract, addKJApplybzbx, myPostFetch } from "@/utils";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      submitMessage: "下一步",
      status: "", //判断是从列表进入还是从表格进
      isLock: false,
      QYSQreportUrl: "",
      JSFWreportUrl: "",
      activeName: "first", //标签页默认
      showAgreementVisible: false, //协议弹框:
      hintVisible: false,
      disabled: false,
      officertel: "", //法人手机号
      operatetel: "", //经办人手机号
      loading: true,
      list: null,
      procedureId: "", // 从路由地址中获取产品ID,保存到状态变量中
      flowId: "",
      productcode: null,
      ProductList: null,
      gsbh: [],
      index: "",
      apply: null,
      b1: false,
      d1: false,
      g1: false,
      h1: false,
      i1: false,
      j1: false,
      form: {
        a: "",
        f: "",
        g: "",
        h: "",
        i: "",
        j: "",
        applyid: "",
        zhapplyid: "",
        businesstype: "",
      },
      // 用户填写资料表格
      addform: {
        a: "",
        f: "",
        g: "",
        h: "",
        i: "",
        j: "",
      },
      // 表单验证
      rules: {
        a: [{ required: true, message: " ", trigger: "blur" }],
        f: [{ required: true, message: " ", trigger: "blur" }],
        g: [{ required: true, message: " ", trigger: "blur" }],
        h: [{ required: true, message: " ", trigger: "blur" }],
        i: [{ required: true, message: " ", trigger: "blur" }],
        j: [{ required: true, message: " ", trigger: "blur" }],
      },
      // 合同签署数据
      contract: {
        // conno: "35555588889885545",
        // contype: "",
        applyid: "",
        entname: "",
        FRaccountid: "",
        inputdate: "",
        JBRaccountid: "",
        licenseno: "",
        mainindname: "",
        officer: "",
        officertel: "",
        ORGaccountid: "",
        productcode: "",
        radio: "",
        ticketadder: "",
        ticketbank: "",
        ticketbankno: "",
        tickethead: "",
        ticketno: "",
        tickettel: "",
        step: "apply",
      },
    };
  },
  // 生命周期方法
  mounted() {
    localStorage.getItem("zhapplyid")
      ? (this.form.businesstype = "1")
      : (this.form.businesstype = "0");
    localStorage.getItem("zhapplyid")
      ? (this.form.zhapplyid = localStorage.getItem("zhapplyid"))
      : "";
    // 从路由地址中获取产品ID,保存到状态变量中
    this.procedureId = localStorage.getItem("productcodeId");
    this.productcode = localStorage.getItem("productcode");
    this.contract.productcode = localStorage.getItem("productcode");
    this.status = this.$route.query.status;
    this.CKBLRZHXKJApplyhx();
    this.findKJApplyhx();
    this.selectkj();
    // this.gsbh = JSON.parse(sessionStorage.getItem("chen"));
  },

  methods: {
    async selectkj() {
      let url = "/api/hubeibusienss/findproductfile";
      let params = {
        productcode: this.productcode,
      };
      let data = await myPostFetch(url, params);
      this.gsbh = data.data.productSub;
      this.gsbh.show05 = data.data.filepath;
    },
    // 点击去签署按钮
    async sign() {
      this.isLock = true;
      setTimeout(() => {
        this.isLock = false;
      }, 10000);
      this.loading = true;
      let data = await Contract(this.contract);
      if (data.code == 100) {
        this.loading = false;
        this.radio = true;
        this.showAgreementVisible = false;
        this.hintVisible = true;
        this.flowId = data.data.flowId;
      }
    },
    // 签署协议提示确认键
    aaaa() {
      this.submitBtns();
      this.hintVisible = false;
    },
    // 表单
    a() {
      this.submitBtns();
    },
    g() {
      this.g1 = false;
      let value = Number(this.form.g);
      this.submitBtns();
      if (this.form.g == "") return;
      this.form.g = value.toFixed(0);
      if (isNaN(this.form.g)) {
        this.form.g = "";
        this.g1 = true;
      }
    },
    h(e) {
      this.h1 = false;
      this.form.h = this.addform.h;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.addform.h = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.addform.h = this.fmoney(this.addform.h);
      let value = Number(this.form.h);
      this.submitBtns();
      if (this.addform.h == "") return;
      this.form.h = value.toFixed(2);
      if (isNaN(this.form.h)) {
        this.addform.h = "";
        this.h1 = true;
      }
    },
    i(e) {
      this.i1 = false;
      this.form.i = this.addform.i;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.addform.i = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.addform.i = this.fmoney(this.addform.i);

      let value = Number(this.form.i);
      this.submitBtns();
      if (this.form.i == "") return;
      this.form.i = value.toFixed(2);
      if (isNaN(this.form.i)) {
        this.form.i = "";
        this.i1 = true;
      }
    },
    j(e) {
      this.j1 = false;
      this.form.j = this.addform.j;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.addform.j = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.addform.j = this.fmoney(this.addform.j);
      let value = Number(this.form.j);
      this.submitBtns();
      if (this.addform.j == "") return;
      this.form.j = value.toFixed(2);
      if (isNaN(this.form.j)) {
        this.addform.j = "";
        this.j1 = true;
      }
    },
    // 正式申请回显
    CKBLRZHXKJApplyhx() {
      if (localStorage.getItem("zhapplyid")) {
        return;
      }
      let url = "/api/hubeibusienss/CKBLRZHXKJApplyhx";
      let parames = {
        productid: this.procedureId,
      };
      myPostFetch(url, parames).then((res) => {
        if (res.data == 0) {
          this.form.applyid = res.data;
          return;
        }
        let data = res.data.kjApplyInfo;
        this.form.applyid = data.applyid;
        this.form.a = data.guarantee;
        this.form.f = data.particularyear;
        this.form.g = data.guaranteedate;
        this.form.h = data.currentasset;
        this.form.i = data.guaranteeamount;
        this.form.j = data.currentliabilities;
        // 企业当期年度资产合计
        !data.currentasset
          ? ((this.addform.h = ""), (this.form.h = ""))
          : (this.addform.h =
              Number(data.currentasset).toLocaleString() + ".00");
        // 担保金额
        !data.guaranteeamount
          ? ((this.addform.i = ""), (this.form.i = ""))
          : (this.addform.i =
              Number(data.guaranteeamount).toLocaleString() + ".00");
        // 企业当期年度负债合计
        !data.currentliabilities
          ? ((this.addform.j = ""), (this.form.j = ""))
          : (this.addform.j =
              Number(data.currentliabilities).toLocaleString() + ".00");
      });
    },
    // 项目管理进入回显
    // /api/hubeibusienss/findKJApplyhx
    findKJApplyhx() {
      if (!localStorage.getItem("zhapplyid")) return;
      let url = "/api/hubeibusienss/findKJApplyhx";
      let parames = {
        applyid: this.form.zhapplyid,
        productid: this.procedureId,
      };
      myPostFetch(url, parames).then((res) => {
        let data = res.data.kjApplyInfo;
        this.form.applyid = data.applyid;
        this.form.a = data.guarantee;
        this.form.f = data.particularyear;
        this.form.g = data.guaranteedate;
        this.form.h = data.currentasset;
        this.form.i = data.guaranteeamount;
        this.form.j = data.currentliabilities;

        // 企业当期年度资产合计
        !data.currentasset
          ? ((this.addform.h = ""), (this.form.h = ""))
          : (this.addform.h =
              Number(data.currentasset).toLocaleString() + ".00");
        // 担保金额
        !data.guaranteeamount
          ? ((this.addform.i = ""), (this.form.i = ""))
          : (this.addform.i =
              Number(data.guaranteeamount).toLocaleString() + ".00");
        // 企业当期年度负债合计
        !data.currentliabilities
          ? ((this.addform.j = ""), (this.form.j = ""))
          : (this.addform.j =
              Number(data.currentliabilities).toLocaleString() + ".00");
      });
    },
    // 点击勾选协议按钮
    async submitBtn() {
      this.radio = !this.radio;
      this.submitBtns();
    },

    // 产品申请第1步
    async addKJApplys() {
      if (this.submitMessage == "提交中") return;
      if (
        this.form.a != "" &&
        this.form.f != "" &&
        this.form.g != "" &&
        this.form.h != "" &&
        this.form.i != "" &&
        this.form.j != ""
      ) {
        this.submitMessage = "提交中";
        let form = {
          guarantee: this.form.a,
          particularyear: this.form.f,
          guaranteedate: this.form.g,
          currentasset: this.form.h,
          guaranteeamount: this.form.i,
          currentliabilities: this.form.j,
          productname: this.gsbh.productname,
          productid: this.procedureId,
          productcood: this.productcode,
          applyid: this.form.applyid,
          zhapplyid: this.form.zhapplyid,
          businesstype: this.form.businesstype,
        };
        let data = await addKJApplybzbx(form);
        if (data.msg == "ok") {
          sessionStorage.setItem("applyid", data.data.applyid);
          this.status
            ? this.$router.push("/gsbzbxApply2?status=lbzs")
            : this.$router.push("/gsbzbxApply2");
          this.submitMessage = "下一步";
        } else {
          ElMessage.error("申请提交失败，请检查数据");
          this.submitMessage = "下一步";
        }
      } else {
        ElMessage.error("请输入内容");
      }
    },
    //
    submitBtns() {
      if (
        this.form.a != "" &&
        this.form.f != "" &&
        this.form.g != "" &&
        this.form.h != "" &&
        this.form.i != "" &&
        this.form.j != "" &&
        this.radio
      ) {
        this.btn = true;
      } else {
        this.btn = false;
      }
    },
    // 表单格式转换
    // 票面金额
    limitInput(value, name) {
      this.addform[name] =
        ("" + value) // 第一步：转成字符串
          .replace(/[^\d^\.]+/g, "") // 第二步：把不是数字，不是小数点的过滤掉
          .replace(/^0+(\d)/, "$1") // 第三步：第一位0开头，0后面为数字，则过滤掉，取后面的数字
          .replace(/^\./, "0.") // 第四步：如果输入的第一位为小数点，则替换成 0. 实现自动补全
          .match(/^\d*(\.?\d{0,2})/g)[0] || "";
    },
    //千分位格式化：10000转为10,000.00
    fmoney(s, n) {
      if (s == "" || s == null || (s == undefined) | isNaN(Number(s))) {
        return s;
      }
      s = Number(s) ? Number(s) : s;
      n = (n || n == 0) && n > -1 && n <= 20 ? n : 2;
      s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
      var l = s.split(".")[0].split("").reverse();
      var r = s.split(".")[1];
      var t = "";
      for (var i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? "," : "");
      }
      if (n > 0) {
        r = "." + r;
      } else if (n == 0) {
        r = "";
      }
      let returnT = t.split("").reverse().join("") + r;
      //负数处理
      if (returnT[0] == "-" && returnT[1] == ",") {
        returnT = "-" + returnT.substring(2);
      }
      return returnT;
    },
    //千分位反格式化:10,000.00转为10000.00
    remoney(s) {
      let str = "";
      if (s) {
        str = String(s).replace(/,/g, "");
      }
      if (s && (s + "").indexOf(".") > -1 && Number(str)) {
        return String(s).replace(/[^\d\.-]/g, "");
      } else if (s && Number(str)) {
        return str;
      } else {
        return s;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  .f1 {
    margin-top: 20px;
    ul {
      display: flex;
      align-items: center;
      li {
        display: flex;
        flex-direction: column;
        height: 40px;
        .icon {
          display: flex;
          align-items: center;
          .icon1 {
            width: 40px;
          }
          .icon2 {
            width: 180px;
            height: 3px;
            background-color: #dbdbdb;
            margin: 0 8px;
          }
          .zssq {
            width: 160px;
          }
        }
        span {
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #999999;
          margin-left: -19px;
          margin-top: 3px;
        }
      }
    }
  }
  .unit {
    position: relative;
    width: 90%;
    height: 20px;
    font-size: 16px;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: #b3b3b3;
    font-size: 14px;
    color: #606266;
    p {
      position: absolute;
      @media only screen and (min-width: 1580px) and (max-width: 1950px) {
        right: 15.1%;
      }
      right: 5.5%;
      top: -3px;
    }
  }
  .f2 {
    // height: 240px;
    overflow: auto;
    // background-color: #f00;
    // @media only screen and (min-width: 1580px) and (max-width: 1950px) {
    //   height: 390px;
    // }
    margin-top: 5%;
    width: 100%;
    ul {
      display: flex;
      flex-direction: column;
      justify-content: center;

      li {
        position: relative;
        width: 90%;
        margin-bottom: 18px;
        height: 50px;
        display: flex;
        // justify-content: center;
        .message {
          position: absolute;
          top: 35px;
          font-size: 12px;
          font-family: Source Han Sans SC;
          font-weight: 300;
          color: #ef2d46;
        }
      }
    }
  }
  .f2::-webkit-scrollbar {
    width: 5px;
    height: 10px;
    background-color: #fff;
  }

  .f2::-webkit-scrollbar-thumb {
    border-radius: 2px;
    background: rgba(36, 143, 172, 0.5);
  }
  .f3 {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    bottom: 55px;
    @media only screen and (min-width: 1580px) and (max-width: 1950px) {
      bottom: 70px;
    }
    width: 275px;
    height: 34px;
    background: #0a7be0;
    border-radius: 4px;
    font-size: 18px;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: #ffffff;
    cursor: pointer;
  }
  // 服务协议
  .agreement {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 25px;
    text-align: center;
    margin-top: 10px;
    user-select: none;
    span {
      font-size: 14px;
      color: #666;
      margin-left: 7px;
    }
    img {
      width: 15px;
      height: 15px;
      cursor: pointer;
    }
    a {
      cursor: pointer;
      font-size: 14px;
      color: #0a7be0;
    }
  }
  // 按钮组
  .submit {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 50px;
    margin: 5px 0 5px 0;
    cursor: pointer;
    .btn {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 180px;
      height: 34px;
      background: #0a7be0;
      border-radius: 4px;
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 300;
      color: #ffffff;
      margin-right: 30px;
    }
    .btn1 {
      background-color: #bfbfbf;
    }
    // 提交按钮
    .btn3 {
      background-color: #ccc;
      &.active {
        background-color: #0a7be0;
      }
      &.actives {
        background-color: rgba(10, 123, 224, 0.6);
      }
    }
  }
}

::v-deep(.hint .el-dialog__body) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 20px;
}

::v-deep(.el-dialog__header) {
  border: 0;
  padding: 5px 20px;
}
/* 输入框样式  */
::v-deep(.el-input__inner) {
  box-sizing: border-box;
  width: 280px;
  height: 39px;
  font-size: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 0px;
  padding: 10px 10px;
  color: #606266;
  outline: 0;
  line-height: 35px !important;
}
::v-deep(.el-input__prefix) {
  position: absolute;
  right: 7px;
}
::v-deep(.el-input__wrapper) {
  width: 280px;
  height: 39px;
}
::v-deep(.enterpriseName .el-input__inner) {
  width: 280px;
}
::v-deep(.enterpriseName .el-select) {
  width: 300px;
}

::v-deep(.el-date-editor.el-input, .el-date-editor.el-input__inner) {
  width: 280px;
}
/* 时间选择器 */
::v-deep(.el-input--large .el-input__wrapper) {
  padding: 1px 5px 1px 11px;
}
</style>
<style lang="scss"></style>
